import json


def main():
    src_path = './output/book_reduce.json'
    dst_json17_path = './sources_17.json'
    dst_json18_path = './sources_18.json'

    with open(src_path, 'r', encoding='utf-8') as f:
        src_books = json.load(f)

    dst_books17 = []
    dst_books18 = []
    for book in src_books:
        if not book.get('bookSourceGroup') or (
                '17' not in book['bookSourceGroup'] and '18' not in book['bookSourceGroup']):
            dst_books17.append(book)
        elif '17' in book['bookSourceGroup']:
            dst_books17.append(book)
        else:
            dst_books18.append(book)

    with open(dst_json17_path, 'w', encoding='utf-8') as f:
        json_str = json.dumps(dst_books17)
        f.write(json_str)

    with open(dst_json18_path, 'w', encoding='utf-8') as f:
        json_str = json.dumps(dst_books18)
        f.write(json_str)


if __name__ == '__main__':
    main()